# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/17 19:44
# @Author   : Robot-Zsj
"""
description:

i:
10 10 56 34 99 1 87 8 99 3 255 6 99 5 255 4 99 7 255 2 99 9 255 21
3 4

o:
99
"""
nums = list(map(int, input().split()))
x, y = map(int, input().split())


def getResult():
    rows = nums[0]
    cols = nums[1]

    graph = [-1] * (rows * cols)

    start = 0
    for i in range(2, len(nums), 2):
        gray = nums[i]
        length = nums[i + 1]

        graph[start:start + length] = [gray] * length
        start += length
    return graph[x * cols + y]


print(getResult())
